﻿using Estsh.Core.Controllers;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Wms.IServices;
using Microsoft.AspNetCore.Mvc;

namespace Estsh.Core.Web.Plugin.Wms.Areas.wms.Controllers.InStock
{
    [Route("wms/[controller]")]
    [ApiController]
    public class SemiFinishInStockController : WmsBaseController
    {
        private ISemiFinishInStockService service;

        // GET: LoginController
        public SemiFinishInStockController(ISemiFinishInStockService _service)
        {
            service = _service;
        }

        [HttpPost("CheckRK")]
        public IActionResult CheckRK(Newtonsoft.Json.Linq.JObject jobj)
        { 
            string RKNO = jobj["RKNO"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                string obj = service.CheckRK(RKNO);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("checkProduct")]
        public IActionResult checkProduct(Newtonsoft.Json.Linq.JObject jobj)
        {
            string productNo = jobj["productNo"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                string obj = service.checkProduct(productNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("UpdateStock")]
        public IActionResult UpdateStock(Newtonsoft.Json.Linq.JObject jobj)
        {
            string locateName = jobj["locateName"].ToString().Trim();
            string RKno = jobj["RKno"].ToString().Trim();
            string productNo = jobj["productNo"].ToString().Trim();
            string Num = jobj["Num"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();
            
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                string obj = service.UpdateStock(locateName,RKno,productNo,Num, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

    }
}
